package com.iyoudoock.citymine.activity.user;

import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.iyoudoock.citymine.BaseActivity;
import com.iyoudoock.citymine.R;
import com.iyoudoock.citymine.constants.Key;
import com.iyoudoock.citymine.constants.Value;
import com.kvin.toolkit.utils.JumpUtils;
import com.kvin.toolkit.utils.StringUtils;
import com.kvin.toolkit.utils.system.AnimUtils;
import com.kvin.toolkit.widget.CountDownView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ForgetPswActivity extends BaseActivity {

    @BindView(R.id.phone_et)
    EditText phoneEt;
    @BindView(R.id.verify_code_btn)
    CountDownView verifyCodeBtn;
    @BindView(R.id.verify_code_et)
    EditText verifyCodeEt;
    @BindView(R.id.next_btn)
    Button nextBtn;
    private String phoneNo;
    private String verifyCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_psw);
        ButterKnife.bind(this);

    }

    @Override
    public void init() {
        this.verifyCodeBtn.setOnClickListener(this);
        this.nextBtn.setOnClickListener(this);

        phoneNo = mPersistentUtils.readString(Key.User.TELEPHONE);
        if (!StringUtils.isEmpty(phoneNo)) {
            this.phoneEt.setText(phoneNo);
        }
    }

    /**
     * initialize
     */
    @Override
    public void initNav() {
        setTitle("忘记密码");
    }


    @Override
    public void onClick(View v) {
        phoneNo = phoneEt.getText().toString();
        verifyCode = verifyCodeEt.getText().toString();
        switch (v.getId()) {
            case R.id.next_btn:
                checkVerifyCode(phoneNo, verifyCode);
                break;
            case R.id.verify_code_btn:
                verifyCodeBtn.startCount();
                getVerifyCode(phoneNo, Value.VERIFY_UPDATE);
                break;
        }
    }


    @Override
    public void onHandleMessage(Message msg) {
        super.onHandleMessage(msg);
        switch (msg.what) {
            case Value.Message.VERIFY_SUCCESS:
                mBundle = new Bundle();
                mBundle.putString(Key.User.TELEPHONE, phoneNo);
                JumpUtils.jumpWithParams(getActivity(), ResetPswActivity.class, null, mBundle, true, AnimUtils.getDefaultJumpAnim());
                break;
        }
    }
}
